package seatiger.tomcat.catalina.core;

import seatiger.tomcat.catalina.*;
import seatiger.tomcat.catalina.connector.http.HttpRequestImpl;
import seatiger.tomcat.util.StringManager;

/**
 * Host 容器对应的映射器
 */
@Deprecated
public class StandardHostMapper implements Mapper {

    private StandardHost host;

    private String protocol;

    private static final StringManager sm = StringManager.getManager(Constants.PACKAGE_CORE);

    @Override
    public Container getContainer() {
        return this.host;
    }

    @Override
    public void setContainer(Container container) {
        if (!(container instanceof StandardHost))
            throw new IllegalArgumentException(sm.getString("httpHostMapper.container"));
        host = (StandardHost) container;
    }

    @Override
    public String getProtocol() {
        return this.protocol;
    }

    @Override
    public void setProtocol(String protocol) {
        this.protocol = protocol;
    }

    @Override
    public Container map(Request request, boolean update) {
        HttpRequestImpl request1 = (HttpRequestImpl) request;
        String requestURI = request1.getRequestURI();
        Context context = host.map(requestURI);
        request.setContext(context);
        ((HttpRequest) request).setContextPath(context.getPath());
        return context;
    }
}
